package com.jf.yytgd.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jf.yytgd.converter.CommentConverter;
import com.jf.yytgd.entity.bean.Comment;
import com.jf.yytgd.dao.CommentMapper;
import com.jf.yytgd.entity.dto.comment.CommentCreateDTO;
import com.jf.yytgd.service.CommentService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

/**
 * Created with IntelliJ IDEA
 * Description: 评论服务层实现
 * User:22954
 * Date:2025-01-13
 * Time:12:59
 */
@Service
public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment> implements CommentService {
    @Resource
    private CommentMapper commentMapper;
    @Override
    public void comment(CommentCreateDTO commentDTO) {
        commentDTO.setRelatedType("Comment");
        Comment comment = CommentConverter.INSTANCE.toBean(commentDTO);
        commentMapper.insert(comment);
        comment = commentMapper.selectById(comment.getRelatedId());
        comment.setComments(comment.getComments() + 1);
        commentMapper.updateById(comment);
    }
}
